package com.yxkj.syh.app.huarong.views;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.syh.app.basic.utils.ComUtil;
import com.yxkj.syh.app.huarong.R;

import chihane.jdaddressselector.AddressSelector;
import chihane.jdaddressselector.OnAddressSelectedListener;
import mlxy.utils.Dev;

/**
 * 创建者：SYH
 * 时间：2020/5/28 14:12
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class AddressDialog extends Dialog {
    private AddressSelector selector;

    public AddressDialog(Context context) {
        super(context, R.style.bottom_dialog);
        init(context);
    }

    public AddressDialog(Context context, int themeResId) {
        super(context, themeResId);
        init(context);
    }

    public AddressDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    private void init(Context context) {
        selector = new AddressSelector(context);
        setContentView(selector.getView());

        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = Dev.dp2px(context, 256);
        window.setAttributes(params);

        window.setGravity(Gravity.BOTTOM);
    }

    public void setOnAddressSelectedListener(OnAddressSelectedListener listener) {
        this.selector.setOnAddressSelectedListener(listener);
    }

    public static AddressDialog show(Context context) {
        return show(context, null);
    }

    public static AddressDialog show(Context context, OnAddressSelectedListener listener) {
        AddressDialog dialog = new AddressDialog(context, R.style.bottom_dialog);
        dialog.selector.setOnAddressSelectedListener(listener);
        dialog.show();

        return dialog;
    }

    public AddressSelector getSelector() {
        return selector;
    }
}
